<?php
	/**
	 * Автокомплит для изменения исключений списка запасов.
	 * 
	 * @author Костин Алексей Васильевич aka Volt(220)
	 * @copyright Copyright (c) 2010, Костин Алексей Васильевич
	 * @license http://www.gnu.org/licenses/gpl-3.0.html GNU Public License
	 * @version 1.0
	 * @package HomeMoney
	 */

	/**
	 * Подключение настроек. 
	 */
	require_once("../ini.php");
	$DBCon=SQLDBFactory::getDB();


	if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
		if($_GET['q']){
			$newItem=$DBCon->escape($_GET['q']);
		
			switch ($_GET["type"]){
				case "idCat": 
					$sql="select cat from categ where cat like '$newItem%' and 
						id not in (select id_smth from spisException where typeEx='c')";
				break;
			
				case "idGood": 
					$sql="select item from goods where item like '$newItem%' and 
						id not in (select id_smth from spisException where typeEx='g')";
				break;

				case "idExC": 
					$sql="select cat from spisExceptions as se
						left outer join categ on categ.id=se.id_smth and se.typeEx='c' where categ like '$newItem%'";
				break;
			
				case "idExG": 
					$sql="select item from spisExceptions as se
						left outer join goods on goods.id=se.id_smth and se.typeEx='g' where item like '$newItem%'";
				break;
			}

			$DBCon->select($sql);
			while($mas=$DBCon->fetchRow()){
				echo $mas[0],PHP_EOL;
			}  	
  		}
	}
?>